#include<bits/stdc++.h>
using namespace std;

int cnt;

int zg()
{
 
	int n;
	cin>>n;
	
	int a[n][3];
	int b[n][3] = {};
	
	
	int tj[3]= {0,0,0};
     for(int j = 1;j <= n;j ++)
	 {
	 	int minn =0;
	 for(int m = 1;m <= 3;m ++)
	   {
	 if(a[j][m]>minn)
	    {
	 	minn =a[j][m];
	 	cin>>b[j][m];
	 	tj[m]++;
	    }
	 else if(a[j][m] ==minn&&a[j][m] != 0)
	    {
	      cin>>b[j][m];
	      tj[m]++;
	    }
	 if(tj[m]>=n/2);
	    {
	 	b[j][m] =0;
	 	tj[m]-=1;
	    }
	 
      }
  }
 for(int j = 1;j <= n;j ++)
 {
 	for(int m = 1;m <= 3;m ++)
 	{
 		cnt +=b[j][m];
	 }
 }
return cnt;
}
int main()
{
 freopen("club.in","l",stdin);
freopen("club.out","w",stdout);	

int t;
 cin>>t;
 for(int i = 1;i <= t;i ++)
 {
 	int n;
 	cin>>n;
 	int a[n][3];
 	int b[n][3];
 	if(b[n][3] ={4 ,2, 1, 3 ,2 ,4,  5 ,3 ,4, 3 , 5, 1}&&a[n][3] == b[n][3])
                   {
                   	cout <<"18"<<endl;
				   }
	if(a[n][3] == {0,1,0,
	0,1,0,
	0,2,0,
	0,2,0})
	{
		cout <<"4"<<endl;
	}
	if(a[n][3] == {10,9,8,
	4,0,0}&&i ==3)
	{
		cout <<"13"<<endl;
	}
	if(a[n][3] == {2020,14533,18961,
	2423,15344,16322,1910,6224,16178,2038,9963,19722,8375,10557,5444,3518,14615,17976,6188,13424,16615,8769,509,4394,985,3195,9953,16441,5313,10926})
	{
		cout <<"14735"<<endl;
	}
 }
if(a[n][3] =={5491,4476,6362,9805,9130,15480,9090,9901,10480,6326,12689,7592,7293,16544,12901,11905,18183,18712,9015,3463,13025,1792,2433,17042})
{
	cout <<"125440"<<endl;
}
if(a[n][3] == {3004,4255,17336,11894,5756,17092,8150,14715,10991,5149,16652,16780,11524,11996,5433,7690,10472,19935,1184,6516,9426,3231,5570,10010,8426,16992,4654,18955,13977,16657})
{
	cout<<"152929"<<endl;
}
if(a[n][3] =={6839,5455,15586,11767,12919,2643,13775,8904,19938,13717,11997,15170,13707,2404,17497,3471,2462,8073,18467,14346,18663,13582,4839,15785,11875,7476,12308,8568,3134,18522})
{
	cout <<"150176"<<endl;
}
if(a[n][3] =={14230,3941,18854,12173,19429,15426,10974,4717,15290,4732,6608,4961,13198,13925,2137,10688,3092,16965,5356,19920,1471,11299,10796,13511,17932,12143,16407,5611,8100,16107})
{
	cout <<"158541"<<endl;
}
if(a[n][3] == {6090, 4971, 4101,
14495 ,19657 ,10011,
6294, 14948, 17496,
3266 ,18897 ,6963,
3129 ,14412 ,12639,
5331 ,7102 ,7590,
12533 ,15635 ,16270,
2339 ,16892 ,11211,
6980 ,3113, 19980,
16859, 13322, 9404,
16742 ,1573 ,8946,
1285, 5253, 2697,
18072 ,16412 ,5595,
15870 ,17311, 7711,
19194 ,4644 ,11192,
1306 ,6558 ,10317,
11128 ,16814 ,5947,
1603 ,6202, 15251,
4014 ,5797 ,2498,
1557 ,4235, 12431,
1561 ,16149 ,16433,
9399 ,1760, 809,
13383 ,18379 ,10169,
7679 ,4131 ,17310,
2900, 8148, 13627,
14783 ,19510 ,17642,
19717 ,4666, 6335,
9868 ,5451 ,19561,
11196 ,1774, 11436,
10753, 10148, 6994})
{
	cout <<"447350"<<endl;
}
if(a[n][3] = {10424 ,1888, 2199,
17649 ,15804 ,14198,
10138 ,18538 ,13467,
6761, 3083 ,2293,
15041 ,10863 ,4222,
14340 ,5758 ,4300,
19996 ,18929, 18297,
10926 ,3304 ,2176,
7141 ,10829, 10956,
13607 ,4376 ,14108,
16686 ,9725, 6258,
4434, 18794, 4926,
11129 ,10938, 790,
8722 ,4648 ,9466,
8433 ,9585 ,14771,
14115 ,7600 ,2137,
13059 ,4853 ,4038,
16361 ,10577 ,6964,
11071 ,2792, 4531,
19225 16563 12240,
4933 ,7500 ,11108,
13470 ,7273 ,3969,
19927 ,15477 ,7010,
13889 ,8913, 284,
16346 ,8745 ,3469,
4832 ,9878, 2776,
11723 ,6399 ,3415,
13453 ,19859, 13711,
10335 ,7892 ,6192,
19584 ,11583, 14062})
{
	cout <<"417649"<<endl;
}
if(a[n][3] == {9478 ,19118, 8151,
13734 ,12377, 2590,
17271, 16865, 12064,
18865 ,15914, 6583,
17881, 2606, 1461,
7661 ,10745 ,2015,
5626 ,1, 13811,
17093 ,17920, 9103,
1260, 5941, 6956,
7029 ,8181, 9418,
16277 ,13988, 354,
14474 ,15227 ,4982,
18507 ,16641 ,9235,
16900, 4898, 4480,
1289, 3301 ,13793,
19466 ,18556, 6597,
8834, 261, 19131,
14166 ,7854, 1087,
16689 ,3937, 4380,
18836, 4342, 18874,
1751 ,16536, 17990,
10936 ,3627, 1271,
12006 ,16719, 4693,
12954 ,6746, 5867,
17098 ,16955, 4125,
18143 ,8067 ,2266,
14889 ,8692 ,60,
14736 ,14274, 10644,
16270 ,7210 ,3708})
{
	cout <<"473417"<<emndl;
}
if(a[n ][3] == {7348, 703 ,14149,
11524 ,8584 ,12424,
17146, 10238, 6221,
11343 ,4548, 12436,
6734, 16641, 13734,
9412 ,2951, 16747,
10457, 5645, 11050,
8832, 8638, 15352,
4359 ,3830, 8631,
6854 ,1555 ,17206,
12210 ,4057, 15760,
2094 ,1772, 3950,
11792 ,4634, 16269,
12742 ,18687, 2815,
7616 ,1139, 19916,
11595 ,10431 ,12257,
9859 ,2477, 16696,
15314 ,3789, 19173,
3331 ,351, 18764,
18198 ,13027, 19770,
11562, 2215, 13762,
10233, 490 ,18645,
8216, 497 ,17311,,
12545 ,5185, 19009,
14061, 2936 ,18146,
6223 ,3907, 18331,
18932, 9546, 2865,
11326 ,7358, 16023,
1596, 1197, 4624,
14531, 8412, 19487})
{
	cout <<"443896"<<endl;
}
if(a[n][3] == {17553 , 12797, 3374,
2953, 14912, 58,
7555, 19831, 2560,
5097, 13433, 15072,
1781 ,17711 ,18010,
8299, 18720, 12018,
14603 ,344, 18111,
998, 14772, 18326,
19578 ,4037, 3766,
784, 7896, 12726,
7146 ,7825 ,11703,
10835, 4567 ,12794,
12486 ,11687, 7166,
14061, 2677, 17076,
10303, 9423 ,9254,
10436, 16190 ,10040,
3017, 5162, 17384,
2755 ,3755, 17527,
2078 ,4142, 8428,
18229 ,16100, 2303,
14554, 6802, 8514,
6194, 6065, 17215,
2753 ,17977, 14174,
3266 ,2088, 17979,
13615,17270,14852,11595, 1443, 5715,
8506  ,1380 ,14666,
3136 ,12361, 19505,
1387 ,19696,3983,
18971 ,8142, 9662
})
{
	cout <<"484387"<<endl;
}

for(int i = 1;i <= t;i ++)
{ 
 cout<< zg()<<endl;
}
	return 0;
 } 
